# Contributor: Steeve Chailloux <steeve.chailloux@orus.io>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Mitch Tishmack <mitch.tishmack@gmail.com>
pkgname=cabal-stage0
# Latest release (3.6.2.0) is very very difficult to bootstrap with GHC 9.X
pkgver=0_git20211105
_commit=5b4258cbfa536b6362c4e20578ced51676206ea8
pkgrel=3
pkgdesc="Cabal version used for bootstrapping"
url="https://haskell.org/"
arch="x86_64" # Limited by GHC
license="BSD-3-Clause"
depends="gmp zlib !cabal"
makedepends="ghc gmp-dev libffi-dev zlib-dev python3"
options="net !check" # TODO: enable tests
source="$pkgname-$pkgver.tar.gz::https://github.com/haskell/cabal/archive/$_commit.tar.gz
	depends-for-ghc-9.0.1.patch

	linux-9.0.1.json"
builddir="$srcdir/cabal-$_commit"

# Provide cabal-bootstrap for community/cabal.
# See comment in community/cabal for details.
provides="cabal-bootstrap"
provider_priority=1 # lowest

prepare() {
	default_prepare
	cp "$srcdir"/linux-9.0.1.json "$builddir/bootstrap"
}

build() {
	./bootstrap/bootstrap.py \
		-d ./bootstrap/linux-9.0.1.json \
		-w "$(command -v ghc)"
}

package() {
	install -m 755 -D _build/bin/cabal "$pkgdir/usr/bin/cabal"
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

sha512sums="
7e54a6408b04e6f7988eae140d99089f1a69c5e8322e2eedcd0ea9559b569c74cc67a81507868b2a5942461cad8c0275be9b8e5452e778b8b25090a69b287668  cabal-stage0-0_git20211105.tar.gz
22d2ebe44fe651d2e52d00a46c62619f0980bd03d486c7e8afd22de074f2cc47ca42275533007416d8a06b330302ef02d610dd02fe546b607d7bdb4286f485da  depends-for-ghc-9.0.1.patch
2e9c055867ed6e02c27c2c119e939a019354c0765844295714b7cd4d2c3f5693405ef7c1c0007c1eaf6055a76033aec4825f61fdabaa04d6e6da5d56c71c90c8  linux-9.0.1.json
"
